<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>

	<head>
		<title>系统设置-用户管理</title>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
	</head>

	<body>
		<div id="mainContent">
			<div id="mainContent_content">
				<div class="page_header">
					<a>用户管理</a>
				</div>

				<div class="search">
					<form class="form" method="post" action="<%=basePath%>user/selectByWhere.do">
						<label>用户名</label>
						<input type="text" id="loginname" name="loginname" value="${userPage.loginname}" class="form-control"></input>
						<input type="hidden" name="currentPage" value="1">

						<span class="btn"> 
						<input type="submit" value="查询" class="btn btn1"></input>
						<input type="button" value="清空" onclick="clearSearchParam();" class="btn btn2"></input>
						<c:if test="${isAdd }">
							<input type="button" value="新增" onclick="toAddUser();" class="btn btn1"></input> 
						</c:if>
						<input type="button" value="编辑" onclick="toEditSupplier();" class="btn btn2"></input>
						<c:if test="${isDelete }">
							<input type="button" value="删除" onclick="toDeleteSupplier();" class="btn btn_danger"></input>
						</c:if>
					</span>
					</form>
				</div>

				<div class="tableBox box">
					<table class="table table-bordered table_text_center">
						<thead>
							<tr>
								<th></th>
								<th>操作</th>
								<th>登录账户</th>
								<th>用户名称</th>
								<th>用户状态</th>
								<th>用户角色</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${user }" var="user" varStatus="i">
								<tr onclick="selectRow(this);">
									<td>
										<label class="radio"><input type="radio" name="operateSupplier" value="${user.userid }"><span class="radio_icon"></span></label>
									</td>
									<td>
										<a class="btn btn-xs btn1" onclick="toUpdateUser(${user.userid });">编辑</a>
										<c:if test="${isDelete }">
											<a class="btn btn-xs btn_danger" onclick="confirmDeleteUser(${user.userid });">删除</a>
										</c:if>
									</td>
									<td>${user.accountName}</td>
									<td>${user.loginname}</td>
									<td>${user.status}</td>
									<td>${user.rolename}</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
				<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
			</div>
			<jsp:include page="/jsp/system/user/adduser.jsp"></jsp:include>
			<jsp:include page="/jsp/system/user/updateuser.jsp"></jsp:include>
			<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
		</div>
		<script src="<%=basePath%>js/jquery-3.2.1.min.js"></script>
		<script src="<%=basePath%>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<script src="<%=basePath%>js/public.js"></script>
		<script type="text/javascript">
			//清空搜索条件
			function clearSearchParam() {
				$(".search input:text").val("");
				$(".search select").val("");
			}

			function selectRow(obj) {
				$(obj).find('input:radio[name="operateSupplier"]')[0].checked = true;
			}

			function toEditSupplier() {
				var radio = $('input:radio[name="operateSupplier"]:checked');
				if(!radio.val()) {
					Prompt.alert("提示", "请先选中需要编辑的用户！");
					return;
				}
				toUpdateUser(radio.val());
			}

			function toDeleteSupplier() {
				var radio = $('input:radio[name="operateSupplier"]:checked');
				if(!radio.val()) {
					Prompt.alert("删除提示", "请先选中需要删除的用户！");
					return;
				}
				confirmDeleteUser(radio.val());
			}

			function confirmDeleteUser(id) {
				var delFunc = function() {
					$.ajax({
						url: "<%=basePath%>user/delectuser2.do",
						type: "post",
						async: false,
						dataType: "json",
						data: "id=" + id,
						success: function(data) {
							if(data.result == "success") {
								Prompt.alert("删除提示", "用户已删除！");
								location.href = location.href;
							} else {
								Prompt.alert("删除提示", "删除失败！");
							}
						},
						error: function() {
							Prompt.alert("删除提示", "服务器无响应，请刷新页面后重试！");
						}
					});
				}
				Prompt.confirm("提示", "确认要删除该用户吗?删除后无法恢复", delFunc);
			}
		</script>
	</body>

</html>